#include "hardwaredriver.h"
#include "globalconfig.h"

HardwareDriver::HardwareDriver(QObject *parent) : QObject(parent), beepInterval(500), beeping(false), lightAuto(false)
{
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(slotTimer()));
    timer->setInterval(beepInterval);
    timer->setSingleShot(true);

    //蜂鸣器声音设置
    setBeeperVolume(5);
    beepEnable = true;
}

HardwareDriver::~HardwareDriver()
{

}

void HardwareDriver::startBeep(bool continuously)
{
#if M1515
    if(avic_get_currentBoardId()!=avic_get_mainBoardId())
        return;
#endif
    if(beepEnable)
    {
        if(beeping)
            return;
#if M1515
        avic_set_beep(1);
#endif
        beeping = true;
        if(!continuously)
            timer->start();
    }
}

void HardwareDriver::stopBeep()
{
#if M1515
    avic_set_beep(0);
#endif
    timer->stop();
    beeping = false;
}

void HardwareDriver::slotTimer()
{
    stopBeep();
}

void HardwareDriver::setBeeperVolume(int level)
{
#if M1515
    beepVolume = level;
#endif
}

bool HardwareDriver::setBeeperTime(int msec)
{
    if(beeping || timer==NULL)
        return false;
    beepInterval = msec;
    timer->setInterval(msec);
    return true;
}

void HardwareDriver::setBrightness(int val)
{
#if defined(Q_OS_LINUX)
    if(val == 0)
    {
        avic_SetAutoBrightness(1);
    }
    else if(val>0 && val<=200)
    {
        avic_SetManualBrightness(val);
    }
#endif
}

void HardwareDriver::setBeepEnable(bool rxEnable)
{
    beepEnable = rxEnable;
}
